package cn.wolfcode.springcloud.feign;

import cn.wolfcode.springcloud.domain.Product;
import cn.wolfcode.springcloud.service.IProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class ProductFeignClient implements ProductFeignApi {

    @Autowired
    private IProductService productService;

    @Value("${server.port}")
    private String port;

    @Override
    public Product get(Long id) {
        System.out.println("ProductFeignClient..get...");

        //记录调用日志
        log.info("ProductController.get....");

        Product product = productService.get(id);
       // int  i  = 1/0;


        //想让order-server服务调用product集群时,知道调用哪一个服务(8080?8081?)
        //product.setName(product.getName() + "-" + port);

       /* try {
            Thread.sleep(3000); //延时3秒
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/

        //防止端口重复拼接
        Product pp = new Product();
        BeanUtils.copyProperties(product,pp);
        pp.setName(product.getName() + "-" + port);
        return pp;
    }
}